﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YunBox2.Contracts.Core;

namespace YunBox2.Client.Infrastructure.ViewModels
{
	public abstract class BizObjectEditorViewModel<T>:DomainObject where T:BizObject
	{
		protected BizObjectEditorViewModel()
		{
			
		}

		private T _dataItem;
		public virtual T DataItem
		{
			get
			{
				return _dataItem;
			}
			set
			{
				if(_dataItem!=value)
				{
					_dataItem = value;
					RaisePropertyChanged("DataItem");
				}
			}
		}

		private bool _isReadOnly = true;

		public virtual bool IsReadOnly
		{
			get
			{
				if (DataItem == null)
					return true;
				return DataItem.IsReadOnly && !IsCreating && _isReadOnly;
			}
			set
			{
				if (_isReadOnly != value)
				{
					_isReadOnly = value;
					RaisePropertyChanged("IsReadOnly");
				}
			}
		}

		private bool _isCreating = false;
		public virtual bool IsCreating
		{
			get
			{
				return _isCreating;
			}
			set
			{
				if(_isCreating!=value)
				{
					_isCreating = value;
					RaisePropertyChanged("IsCreating","IsReadOnly");
				}
			}
		}

		private bool _isEditing = false;
		public virtual bool IsEditing
		{
			get
			{
				return !IsReadOnly && (IsCreating || _isEditing);
			}
			set
			{
				if(_isEditing!=value)
				{
					_isEditing = value;
					RaisePropertyChanged("IsEditing");
				}
			}
		}

		private bool _creatable = true;
		public virtual bool Creatable
		{
			get
			{
				return _creatable;
			}
			set
			{
				if(_creatable!=value)
				{
					_creatable = value;
					RaisePropertyChanged("Creatable");
				}
			}
		}

		private bool _editable = true;
		public bool Editable
		{
			get
			{
				return _editable;
			}
			set
			{
				if(_editable!=value)
				{
					_editable = value;
					RaisePropertyChanged("Editable");
				}
			}
		}


	}


}
